<style type="text/css">
  .user-header {
    background: #42A3F4;
    color: #fff;
    height: 3.214em;
    margin-bottom: 1em;
  }
  .user-header-back {
    width: 3.214em !important;
    height: 3.214em;
    background: url() center center no-repeat;
    z-index: 1;
  }
  .user-header-title {
    margin-left: -3.214rem;
    text-align: center;
    font-size: 1.2em;
  }
  .form {
    padding-left: 1em;
    padding-right: 1em;
  }
</style>

<header class="user-header flex-row">
  <a class="row-item row-item-auto user-header-back" href="javascript:window.history.back()"></a>
  <h3 class="user-header-title row-item">用户登录</h3>
</header>


<form id="form" class="form" method="post">
  <div class="form-item">
    <input name="name" type="tel" placeholder="请输入手机号码" data-nullmsg="请填写手机号码" required>
  </div>
  <div class="form-item">
    <input name="password" type="password" placeholder="请输入密码" data-nullmsg="请输入密码" required>
  </div>
  <div class="form-item">
    <button type="submit" class="btn btn-blue btn-block">登录</button>
  </div>
  <div class="form-item">
    <a href="__CONTROLLER__/register/sid/{$_GET['sid']}?back={$_GET['back']}">还没有账户？点击注册</a>  
  </div>
</form>

<script type="text/javascript">
 (function(){
  
   var oForm = document.getElementById( "form" ),
       formInput = oForm.getElementsByTagName( "input" ),
       back = "{$_GET['back']}";
  
   oForm.addEventListener( "submit", login, false );
  
   function login( event ) {
    event.preventDefault();
    check(function(){
      var json = GH.serialize("form");
      json.sid = {$sid};
      GH.ajax("__CONTROLLER__/loginPost", json, function(data){
        GH.showMessage( data.msg );
        ( data.error === 0 ) && ( setTimeout(function(){ location.href = back; }, 1000) ); 
      });  
    });
  };
  
  //检查表单
  function check(callback) {
    var i = 0, inputSelf = null;
    for(; inputSelf = formInput[i]; i++){
      if ( inputSelf.getAttribute( "type" ) === "hidden" ) continue;
      if ( inputSelf.value === "" ) {
        GH.showMessage( inputSelf.getAttribute( "data-nullmsg" ) );
        return false;
      };
    };
    callback && callback();
  };
 })();
</script>